package com.elong.qadev.interceptor;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

public class AuthInterceptor extends AbstractInterceptor{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	Logger logger = Logger.getLogger(AuthInterceptor.class);
	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		HttpSession session = ServletActionContext.getRequest().getSession();
		
		logger.debug("开始执行全局拦截器--拦截所有action");
		logger.debug(ServletActionContext.getRequest().getMethod());
		if("GET".equalsIgnoreCase(ServletActionContext.getRequest().getMethod())&&(session.getAttribute("user") == null)){
			logger.debug("action访问为浏览器直接访问，禁止，并返回登录页面");
//			if () {
//				logger.debug("action访问控制session失效时间");
//				return "error";
//			}
			return "error";
		}else{
			return invocation.invoke();
		}
	}

}